package xyz.chaobei.thread.simple;

/**
 * @copyright (C), 2015-2020
 * @fileName: DisLock
 * @author: MRC
 * @date: 2021/1/26 21:51
 * @description:
 */
public class DisLock {

    private int num = 0;

    public void add() {
        System.out.println("DisLock add try catch lock...");
        synchronized (ConstantsB.lock) {
            num++;
            System.out.println("DisLock add try catch lock success");

            System.out.println("DisLock add try catch lockB...");
            synchronized (ConstantsB.lockB) {
                System.out.println("DisLock add try catch lockB success");
                num++;
            }
        }
    }

    public void sub() {
        System.out.println("DisLock sub try catch lockB...");
        synchronized (ConstantsB.lockB) {
            num--;
            System.out.println("DisLock sub try catch lockB success");

            System.out.println("DisLock sub try catch lock...");
            synchronized (ConstantsB.lock) {
                System.out.println("DisLock sub try catch lock success");
                num--;
            }
        }
    }

}
